package config

import (
	"gitee.com/kaylee595/gkaylee/kerr"
	"github.com/spf13/viper"
)

type Config struct {
	DeleteVideoPassword string
	WebStaticPath       string
}

var C = &Config{}

func LoadConfig(filename string) (*Config, error) {
	if len(filename) > 0 {
		viper.SetConfigFile(filename)
	} else {
		viper.AddConfigPath(".")
		viper.SetConfigName("config")
		viper.SetConfigType("yaml")
	}
	err := viper.ReadInConfig()
	if err != nil {
		return nil, kerr.WrapTraceStack(err)
	}
	c := new(Config)
	err = viper.Unmarshal(c)
	if err != nil {
		return nil, kerr.WrapTraceStack(err)
	}
	return c, nil
}
